package cn.stu.projectsummit.school.controller;

import cn.stu.projectsummit.base.response.JsonResult;
import cn.stu.projectsummit.school.pojo.dto.SchoolQuery;
import cn.stu.projectsummit.school.pojo.dto.SchoolSaveParam;
import cn.stu.projectsummit.school.pojo.entity.School;
import cn.stu.projectsummit.school.pojo.vo.SchoolVO;
import cn.stu.projectsummit.admin.pojo.dto.AdminLoginParam;
import cn.stu.projectsummit.admin.pojo.vo.AdminVO;
import cn.stu.projectsummit.base.response.JsonResult;
import cn.stu.projectsummit.school.pojo.dto.SchoolSaveParam;
import cn.stu.projectsummit.school.pojo.dto.SchoolSearch;
import cn.stu.projectsummit.school.pojo.vo.SchoolCount;
import cn.stu.projectsummit.school.service.SchoolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/school")
public class SchoolController {
    @Autowired
    SchoolService schoolService;

    @GetMapping("select")
    public JsonResult selectSchool(SchoolQuery schoolQuery) {
        log.debug("查询学校列表:selectSchool={}", schoolQuery);
        List<SchoolVO> list = schoolService.selectSchool(schoolQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveSchool(SchoolSaveParam schoolSaveParam) {
        log.debug("保存学校:saveSchool={}", schoolSaveParam);
        schoolService.saveSchool(schoolSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteSchool(@PathVariable Long id) {
        schoolService.deleteSchool(id);
        log.debug("删除学校:deleteSchool={}", id);
        return JsonResult.ok();
    }

    @GetMapping("selectCount")
    public JsonResult select(SchoolSearch schoolSearch) {
        log.debug("$$$$$$$$$$$$$$$$$$$$$$"+schoolSearch.getId()+schoolSearch.getSchoolName());
        //调用业务层方法,如果业务层方法成功执行完毕,可以拿到业务层返回的
        List<SchoolCount> list = schoolService.count(schoolSearch);
        //控制层向前端返回登录成功后的完整用户信息userVO
        //将查到的userVO装到.ok()中一起返回给前端
        return JsonResult.ok(list);
    }
}
